package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: zyx
 * @created: 2025-10-09-10:40
 * @description:
 */
@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService ActivityService;

    @GetMapping
    public Result page(@RequestParam(name = "channel", required = false) Integer channel,
                       @RequestParam(name = "type", required = false) Integer type,
                       @RequestParam(name = "status", required = false) Integer status,
                       @RequestParam(name = "page", defaultValue = "1") Integer page,
                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize){
        log.info("分页查询活动,参数：渠道={},类型={},状态={},当前页码={},每页大小={}", channel, type, status, page, pageSize);
        PageResult<Activity> pageResult = ActivityService.page(channel, type, status, page, pageSize);
        return Result.success(pageResult);
    }
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        log.info("查询活动id:{}", id);
        Activity Activity = ActivityService.getById(id);
        return Result.success(Activity);
    }

    @PutMapping
    public Result update(@RequestBody Activity Activity) {
        log.info("修改活动:{}", Activity);
        ActivityService.update(Activity);
        return Result.success();
    }
    @PostMapping
    public Result add(@RequestBody Activity Activity) {
        log.info("添加活动:{}", Activity);
        ActivityService.add(Activity);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除活动id:{}", id);
        ActivityService.delete(id);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result listByType(@PathVariable Integer type) {
        log.info("根据渠道来源查询活动,参数：渠道={}", type);
        List<Activity> list = ActivityService.listByChannel(type);
        return Result.success(list);
    }
}
